/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:        sqbang                                                 *
 * Email:         sqbang@ustc.edu                                        *
 * Date:          2016.08.24                                             *
 *                                                                       *
 *************************************************************************/

//declaration header
#include "COMMON/equa/PhaseChangeGroup.h"

//COMMON headers
#include "COMMON/equa/EquationDomain.h"
#include "COMMON/tbox/InputDatabase.h"
#include "COMMON/tbox/LogMessage.h"

namespace FreeMAPs
{

PhaseChangeGroup::PhaseChangeGroup (
    const EquationDomain* eq_domain):
    Parent (eq_domain->get_full_name(), "phase_changes", false),
    d_equa_domain (eq_domain)
{}



PhaseChangeGroup::~PhaseChangeGroup()
{
    this->clear();
}



void
PhaseChangeGroup::clear()
{
    Utilities::clear_pointer_object (d_phase_change_items);
}



void
PhaseChangeGroup::get_from_input (
    const InputDatabase* db)
{
#if 0
    this->prepare_for_use (db);

    db->insert_allowable_key_with_items ("phase_change_items");

    db->check_allowable_keys ();

    /*
     * build phase_change_items
     */
    {
        db->check_optional_key ("phase_change_items", DataType::STRING, false, true);
        db->check_duplicated_string_value ("phase_change_items");
        if (db->key_exists ("phase_change_items"))
        {
            const std::vector<std::string>& items = db->get_string_vector ("phase_change_items");
            for (std::size_t pos = 0; pos < items.size(); ++pos)
            {
                const std::string& item_name = items [pos];
                db->check_requisite_key (item_name, DataType::DATABASE, false, false);
                PhaseChangeStrategy* item = PhaseChangeStrategy::create_object (
                                                db->get_enum_from_subdatabase <PhaseChangeType> (item_name, "phase_change_type"),
                                                d_equa_domain,
                                                item_name);
                item->get_from_input (db->get_database (item_name));
                d_phase_change_items.insert (std::make_pair (item_name, item));
            }
        }
    }
#endif
}



std::ostream&
operator << (
    std::ostream& os,
    const PhaseChangeGroup& rhs)
{
    os << "phase_change_group\n{\n";

//    os << LogMessage::get_log_info_from_map (
//           "phase_change_items",
//           rhs.d_phase_change_items,
//           ONE_TAB) << '\n';

    os << LogMessage::get_prefix (ONE_TAB) << "phase_change_items = \"" << "melt" << "\"\n\n";
    os << LogMessage::get_prefix (ONE_TAB) << "melt" << "\n";
    os << LogMessage::get_prefix (ONE_TAB) << "{" << "\n";
    os << LogMessage::get_prefix (TWO_TAB) << "phase_change_type      = " << "\"MELT\"" << "\n";
    os << LogMessage::get_prefix (TWO_TAB) << "simple_region_names    = " << "\"_body\"" << "\n";
    os << LogMessage::get_prefix (TWO_TAB) << "criterion              = " << "\"T > 2200\"" << "\n";
    os << LogMessage::get_prefix (TWO_TAB) << "connectivity_type      = " << "\"CONNECTED_TO_BOUNDARY\"" << "\n";
    os << LogMessage::get_prefix (TWO_TAB) << "require_deletion       = " << "TRUE" << "\n";
    os << LogMessage::get_prefix (TWO_TAB) << "require_compensation   = " << "FALSE" << "\n";
    os << LogMessage::get_prefix (ONE_TAB) << "}" << "\n";

    os << "}";

    return os;
}

} // namespace FreeMAPs
